// pages/editAddress/editAddress.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    milkArray: [{//投递奶箱
      id: 0,
      name: "需安装，工作人员和我联系"
    }, 
    {
      id: 1,
      name: "已安装奶箱"
    },
    {
      id: 2,
      name: "已有箱"
    },
    {
      id: 3,
      name: "信箱(位置电话联系)"
    },
    {
      id: 4,
      name: "报箱(位置电话联系)"
    },
    {
      id: 5,
      name: "传达室"
    },
    {
      id: 6,
      name: "不用装"
    }
    ],
    showtext0:true,
    showtext1: true,
    showtext2: true,
    showtext3: true,
    milkIndex: 0,
    mrBtn:false,//是否默认地址
    submitBtn:false//提交
  },
  staticData: {//提交
  },
  textHidden0: function (e) {
    // 获取下标
    var Index = e.currentTarget.dataset.index;
    console.log(Index)
    if (!this.staticData.name&&Index==0) {
      this.setData({
        showtext0: true
      })
    }else{
      this.setData({
        showtext0: false
      })      
    }
  },
  textHidden1: function (e) {
    // 获取下标
    var Index = e.currentTarget.datas
    if (!this.staticData.tel && Index == 1) {
      this.setData({
        showtext1: true
      })
    } else {
      this.setData({
        showtext1: false
      })
    }
  },
  textHidden2: function (e) {
    // 获取下标
    var Index = e.currentTarget.dataset.index;
    console.log(Index)
    if (!this.staticData.address && Index == 2) {
      this.setData({
        showtext2: true
      })
    } else {
      this.setData({
        showtext2: false
      })
    }
  },
  textHidden3: function (e) {
    // 获取下标
    var Index = e.currentTarget.dataset.index;
    console.log(Index)
    if (!this.staticData.beizhu && Index == 3) {
      this.setData({
        showtext3: true
      })
    } else {
      this.setData({
        showtext3: false
      })
    }
  },
  textShow0: function (e) {
    var Index = e.currentTarget.dataset.index;
    if (!this.staticData.name && Index == 0) {
      this.setData({
        showtext0: false
      })
    } 
   
  },
  textShow1: function (e) {
    var Index = e.currentTarget.dataset.index;
    if (!this.staticData.tel && Index == 1) {
      this.setData({
        showtext1: false
      })
    }
  },
  textShow2: function (e) {
    var Index = e.currentTarget.dataset.index;
    if (!this.staticData.address && Index == 2) {
      this.setData({
        showtext2: false
      })
    }

  },
  textShow3: function (e) {
    var Index = e.currentTarget.dataset.index;
    if (!this.staticData.beizhu && Index == 3) {
      this.setData({
        showtext3: false
      })
    }

  },
  milkChange(e) {//选择
    this.setData({
      milkIndex: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  mrBtn:function(){//设置默认
    var mrBtn = this.data.mrBtn
    mrBtn = !mrBtn;
    this.setData({
      mrBtn: mrBtn
    })    
  },
  name(e) {//收货人
    this.staticData.name = e.detail.value.replace(/\s+/g, '');
    this.submitText()
  },
  tel(e) {//手机号
    this.staticData.tel = e.detail.value.replace(/\s+/g, '');
    this.submitText()
  },  
  address(e) {//请输入街道、小区、门牌号等信息
    this.staticData.address = e.detail.value.replace(/\s+/g, '');
    this.submitText()
  },  
  beizhu(e) {//备注
    this.staticData.beizhu = e.detail.value.replace(/\s+/g, '');
  },  
  submitText:function(){
    if (this.staticData.name && this.staticData.tel && this.staticData.address) {
      this.setData({
        submitBtn: true
      });  
    }else{
      this.setData({
        submitBtn: false
      });        
    }
  },
  submit:function(){
    if (!this.staticData.name) {
      wx.showToast({
        title: '请输入姓名',
        icon: 'loading',
        // image:'../images/details/1.png',
        duration: 500
      })
      return;
    }
    if (!this.staticData.tel) {
      wx.showToast({
        title: '请输入手机号',
        icon: 'loading',
        // image:'../images/details/1.png',
        duration: 500
      })
      return;
    }    
    if (!this.staticData.address) {
      wx.showToast({
        title: '请输入地址',
        icon: 'loading',
        // image:'../images/details/1.png',
        duration: 500
      })
      return;
    }  
  }
})